import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue2'
import { normalizePath } from "vite";
import { fileURLToPath } from "node:url";
import viteCompression from 'vite-plugin-compression';
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';

function fromRoot(relativePath) {
  return normalizePath(fileURLToPath(new URL(relativePath, import.meta.url)));
}

// https://vitejs.dev/config/
export default defineConfig({
  // vue2.7: https://blog.vuejs.org/posts/vue-2-7-naruto.html
  plugins: [
    vue(),
    viteCompression({
      algorithm: 'brotliCompress',
    }),
    viteCompression({
      algorithm: "gzip"
    }),
    ViteImageOptimizer({
      /* pass your config */
    }),
  ],
  resolve: {
    // 设置别名
    alias: {
      "@global": fromRoot("./src/global"),
      "@com": fromRoot("./src/components"),
      "@assets": fromRoot("./src/assets"),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@global/inject.scss";`,
      },
    },
  },
  build: {
    minify: true
  }
})
